﻿using Com.Lancetinc.Evs.Data.Domain;
using Com.Lancetinc.Evs.Helpers;

namespace Com.Lancetinc.Evs.ViewModels
{
    public class ExperViewModel : ViewModelBase
    {
        public readonly Exper Exper;

        public ExperViewModel(Exper exper)
        {
            this.Exper = exper;
        }

        private bool _isReadonly;
        public bool IsReadonly
        {
            get => _isReadonly;
            set => SetProperty(ref _isReadonly, value);
        }

        public string SeqNo
        {
            get => Exper.SeqNo;
            set
            {
                if (Exper.SeqNo == value)
                    return;

                Exper.SeqNo = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 病历号
        /// </summary>
        public string MedicalRecordNo
        {
            get => Exper.MedicalRecordNo;
            set
            {
                if (Exper.MedicalRecordNo == value)
                    return;

                Exper.MedicalRecordNo = value;
                RaisePropertyChanged();
            }
        }

        public string BedNo
        {
            get => Exper.BedNo;
            set
            {
                if (Exper.BedNo == value)
                    return;

                Exper.BedNo = value;
                RaisePropertyChanged();
            }
        }

        public string Name
        {
            get => Exper.Name;
            set
            {
                if (Exper.Name == value)
                    return;

                Exper.Name = value;
                RaisePropertyChanged();
            }
        }

        public string Sex
        {
            get => Exper.Sex;
            set
            {
                if (Exper.Sex == value)
                    return;

                Exper.Sex = value;
                RaisePropertyChanged();
                RaisePropertyChanged(nameof(DisplaySex));
            }
        }

        public string DisplaySex
        {
            get
            {
                if (Exper.Sex == "1")
                {
                    return I18nHelper.Default.GetMessage("Male");
                }
                if (Exper.Sex == "0")
                {
                    return I18nHelper.Default.GetMessage("Female");
                }
                return string.Empty;
            }
        }

        public int? Age
        {
            get => Exper.Age;
            set
            {
                if (value == null)
                    return;

                if (Exper.Age == value)
                    return;

                Exper.Age = value.Value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 主治医师
        /// </summary>
        public string AttendingDoctor
        {
            get => Exper.AttendingDoctor;
            set
            {
                if (Exper.AttendingDoctor == value)
                    return;

                Exper.AttendingDoctor = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 助理医师
        /// </summary>
        public string Mediastinus
        {
            get => Exper.Mediastinus;
            set
            {
                if (Exper.Mediastinus == value)
                    return;

                Exper.Mediastinus = value;
                RaisePropertyChanged();
            }
        }

        public string Diagnosis
        {
            get => Exper.Diagnosis;
            set
            {
                if (Exper.Diagnosis == value)
                    return;

                Exper.Diagnosis = value;
                RaisePropertyChanged();
            }
        }

        public string Identity
        {
            get => Exper.Identity;
            set
            {
                if (Exper.Identity == value)
                    return;

                Exper.Identity = value;
                RaisePropertyChanged();
            }
        }

        public string InspectionPosition
        {
            get => Exper.InspectionPosition;
            set
            {
                if (Exper.InspectionPosition == value)
                    return;

                Exper.InspectionPosition = value;
                RaisePropertyChanged();
            }
        }

        public int PrintCount
        {
            get => Exper.PrintCount;
            set
            {
                if (Exper.PrintCount == value)
                    return;

                Exper.PrintCount = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 上次打印时间
        /// </summary>
        public string LastPrintTime => Exper.LastPrintTime;

        public string Notes
        {
            get => Exper.Notes;
            set
            {
                if (Exper.Notes == value)
                    return;

                Exper.Notes = value;
                RaisePropertyChanged();
            }
        }

        public string StartTime
        {
            get
            {
                if (Exper.StartTime is { Length: >= 19 })
                {
                    return Exper.StartTime.Substring(0, 19);
                }
                return Exper.StartTime;
            }
        }

        public string EndTime
        {
            get
            {
                if (Exper.EndTime is { Length: >= 19 })
                {
                    return Exper.EndTime.Substring(0, 19);
                }
                return Exper.EndTime;
            }
        }

        public bool HasVideo => !string.IsNullOrEmpty(StartTime);

        public void Reset()
        {
            this.Exper.Reset();
            base.Refresh();
        }
    }
}
